package com.nbsaas.boot.manufacturing.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.math.BigDecimal;

@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "BOM项目", model = "BOM项目")
@Entity
@Table(name = "bs_bom_item")
@Comment("BOM项目表")
public class BomItem extends AbstractEntity {

    @Comment("BOM ID")
    @FormField(title = "BOM", sortNum = "1", grid = true, type = InputType.select, required = true)
    private Long bomId;

    @Comment("物料ID")
    @FormField(title = "物料", sortNum = "2", grid = true, type = InputType.select, required = true)
    private Long materialId;

    @Comment("项目编号")
    @SearchItem(name = "itemNo", key = "itemNo", label = "项目编号")
    @FormField(title = "项目编号", sortNum = "3", grid = true, required = true)
    @Column(length = 50, nullable = false)
    private String itemNo;

    @Comment("项目名称")
    @FormField(title = "项目名称", sortNum = "4", grid = true)
    @Column(length = 200)
    private String itemName;

    @Comment("用量")
    @FormField(title = "用量", sortNum = "5", grid = true, type = InputType.el_input_number, required = true)
    @Column(precision = 10, scale = 4)
    private BigDecimal quantity;

    @Comment("单位")
    @FormField(title = "单位", sortNum = "6", grid = true)
    @Column(length = 20)
    private String unit;

    @Comment("损耗率(%)")
    @FormField(title = "损耗率(%)", sortNum = "7", grid = true, type = InputType.el_input_number)
    @Column(precision = 5, scale = 2)
    private BigDecimal wasteRate;

    @Comment("实际用量")
    @FormField(title = "实际用量", sortNum = "8", grid = true, type = InputType.el_input_number)
    @Column(precision = 10, scale = 4)
    private BigDecimal actualQuantity;

    @Comment("单位成本")
    @FormField(title = "单位成本", sortNum = "9", grid = true, type = InputType.el_input_number)
    @Column(precision = 10, scale = 2)
    private BigDecimal unitCost;

    @Comment("总成本")
    @FormField(title = "总成本", sortNum = "10", grid = true, type = InputType.el_input_number)
    @Column(precision = 10, scale = 2)
    private BigDecimal totalCost;

    @Comment("项目层级")
    @FormField(title = "项目层级", sortNum = "11", grid = true, type = InputType.el_input_number)
    private Integer level;

    @Comment("父项目ID")
    @FormField(title = "父项目", sortNum = "12", grid = true, type = InputType.select)
    private Long parentItemId;

    @Comment("项目类型")
    @FormField(title = "项目类型", sortNum = "13", grid = true, type = InputType.select)
    @Column(length = 50)
    private String itemType; // MATERIAL-物料, SUB_ASSEMBLY-子装配, OPERATION-工序

    @Comment("是否关键项目")
    @FormField(title = "是否关键项目", sortNum = "14", grid = true, type = InputType.select)
    private Boolean isCritical;

    @Comment("是否可选")
    @FormField(title = "是否可选", sortNum = "15", grid = true, type = InputType.select)
    private Boolean isOptional;

    @Comment("替代物料")
    @FormField(title = "替代物料", sortNum = "16", grid = true)
    @Column(length = 500)
    private String substituteMaterials;

    @Comment("位置")
    @FormField(title = "位置", sortNum = "17", grid = true)
    @Column(length = 100)
    private String position;

    @Comment("技术要求")
    @FormField(title = "技术要求", sortNum = "18", type = InputType.richText, col = 23)
    @Column(columnDefinition = "TEXT")
    private String technicalRequirements;

    @Comment("质量要求")
    @FormField(title = "质量要求", sortNum = "19", type = InputType.richText, col = 23)
    @Column(columnDefinition = "TEXT")
    private String qualityRequirements;

    @Comment("备注")
    @FormField(title = "备注", sortNum = "20", type = InputType.richText, col = 23)
    @Column(length = 1000)
    private String note;

    @Comment("排序")
    @FormField(title = "排序", sortNum = "21", grid = true, type = InputType.el_input_number, sort = true)
    private Integer sort;
} 